package norbert.flickr.controls {
	import mx.controls.Image;
	import mx.logging.ILogger;
	import mx.logging.Log;
	
	public class PhotoPermission extends Image {
		private static var logger: ILogger = Log.getLogger("norbert.flickr.controls.PhotoPermission");
		
		/* PROPERTIES */
		
		[Embed(source="/../resources/icon_private.gif")]
		private var iconPrivate: Class;
		[Embed(source="/../resources/icon_a_bit_private.gif")]
		private var iconFamily: Class;
		[Embed(source="/../resources/icon_a_bit_private.gif")]
		private var iconFriend: Class;
		[Embed(source="/../resources/icon_a_bit_private.gif")]
		private var iconFamilyAndFriend: Class;
		[Embed(source="/../resources/icon_public.gif")]
		private var iconPublic: Class;

		private var _photo: XML = null;
		[Bindable]
		public function get photo(): XML {
			return _photo;
		}
		public function set photo(value: XML): void {
			_photo = value;
			invalidateProperties();
		}
		
		/* METHODS */
		
		override protected function commitProperties(): void {
			super.commitProperties();
			
			if (photo != null) {
				if (photo.@ispublic == 0 && photo.@isfamily == 0 && photo.@isfriend == 0) {
					source = iconPrivate;
					toolTip = "Private";
				} else if (photo.@ispublic == 0 && photo.@isfamily == 1 && photo.@isfriend == 0) {
					source = iconFamily;
					toolTip = "Family";
				} else if (photo.@ispublic == 0 && photo.@isfamily == 0 && photo.@isfriend == 1) {
					source = iconFriend;
					toolTip = "Friend";
				} else if (photo.@ispublic == 0 && photo.@isfamily == 1 && photo.@isfriend == 1) {
					source = iconFamilyAndFriend;
					toolTip = "Family and friend";
				} else if (photo.@ispublic == 1 && photo.@isfamily == 0 && photo.@isfriend == 0) {
					source = iconPublic;
					toolTip = "Public";
				}
			}
		}
		
	}
}
